/*************************
评分等级
* */
<template>
  <div class="boxsty zhiBiao">

      <div :height="searchheight" v-loading.fullscreen.lock="fullscreenLoading">
      <span
        style="float: right; margin-top: -30px; cursor: pointer"
        @click="searchchangeadvanced"
      >{{ searchadvanced ? "收起" : "展开" }}
        <i
          :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
        />
      </span>
      <div v-show="searchadvanced">

          <el-form
            :inline="true"
            :model="scoreForm"
            :rules="dataRule"
            ref="scoreForm"
            class="form-inline" >
            <el-form-item label="评分规则">
              <el-select
                v-model="scoreForm.pfgz"
                placeholder="请选择评分规则"
                class="xiaLa"
                style="width: 100%"
                :clearable="true"
                @change="getFpgz"
              >
                <el-option
                  v-for="(item, index) in pfgzsList"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="占比规则" v-if="zbgz">
              {{scoreForm.ajszb}}占<el-input type="text" v-model.number="scoreForm.ajsz" style="width:5%" max-length="10"></el-input>%&nbsp;&nbsp;
              {{scoreForm.aszb}}占<el-input type="text" v-model.number="scoreForm.asz" style="width:5%" max-length="10"></el-input>%&nbsp;&nbsp;
              {{scoreForm.bszb}}占<el-input type="text" v-model.number="scoreForm.bsz" style="width:5%" max-length="10"></el-input>%&nbsp;&nbsp;
              {{scoreForm.cszb}}占<el-input type="text" v-model.number="scoreForm.csz" style="width:5%" max-length="10"></el-input>%&nbsp;&nbsp;
              {{scoreForm.dszb}}占<el-input type="text" v-model.number="scoreForm.dsz" style="width:5%" max-length="10"></el-input>%&nbsp;
              {{scoreForm.eszb}}占<el-input type="text" v-model.number="scoreForm.esz" style="width:5%" max-length="10"></el-input>%&nbsp;
              {{scoreForm.fszb}}占<el-input type="text" v-model.number="scoreForm.fsz" style="width:5%" max-length="10"></el-input>%&nbsp;
            </el-form-item>
            <el-form-item label="分数规则" v-if="fsgz">
              大于<el-input type="text" v-model="scoreForm.ajsz" style="width:5%" max-length="10"></el-input>{{scoreForm.ajszb}}&nbsp;&nbsp;
              大于<el-input type="text" v-model="scoreForm.asz" style="width:5%" max-length="10"></el-input>{{scoreForm.aszb}}&nbsp;&nbsp;
              大于<el-input type="text" v-model="scoreForm.bsz" style="width:5%" max-length="10"></el-input>{{scoreForm.bszb}}&nbsp;&nbsp;
              大于<el-input type="text" v-model="scoreForm.csz" style="width:5%" max-length="10"></el-input>{{scoreForm.cszb}}&nbsp;&nbsp;
              大于<el-input type="text" v-model="scoreForm.dsz" style="width:5%" max-length="10"></el-input>{{scoreForm.dszb}}&nbsp;&nbsp;
              大于<el-input type="text" v-model="scoreForm.esz" style="width:5%" max-length="10"></el-input>{{scoreForm.eszb}}&nbsp;&nbsp;
              大于<el-input type="text" v-model="scoreForm.fsz" style="width:5%" max-length="10"></el-input>{{scoreForm.fszb}}&nbsp;&nbsp;

            </el-form-item>
          </el-form>
      <div style="border-bottom: 1px solid #b0bde2">

      </div>
      <div class="mod-config" style="margin-top: 10px">

          <div class="pull-right" style="margin-bottom: 10px">
            <el-button
              type="primary"
              style="margin-left: 10px"
              plain
              @click="saveFormData"
              :disabled="canSubmit"
            >保存</el-button
            >
            <el-button
              plain
              type="primary"
              style="margin-left: 10px"
              @click="fnBackOldPage('返回原页面')"
            >返回</el-button
            >
          </div>

        <div>
          <el-table
            style="width: 100%; margin-top: 20px"
            :data="dataList"
            border
            v-show="tabType == 1"
            v-loading="dataListLoading"
            @selection-change="handleSelectionChange"
            ref="table2"
          >
            <!--<el-table-column type="selection" width="55" align="center"></el-table-column>-->
            <el-table-column
              type="index"
              width="80"
              header-align="center"
              align="center"
              label="序号"
            ></el-table-column>
            <el-table-column
              prop="ygbm"
              header-align="center"
              align="center"
              width="120"
              label="员工编号"
              show-overflow-tooltip
            >
              <!-- <template slot-scope="scope">
                 <el-input v-model="scope.row.ygbh" placeholder="员工编号" />
               </template>-->
            </el-table-column>

            <el-table-column
              prop="ygname"
              header-align="center"
              align="center"
              width="120"
              label="考核对象"
              show-overflow-tooltip
            >
              <!--  <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.name"
                    placeholder="姓名"
                  />
                </template>-->
            </el-table-column>
            <el-table-column
              prop="deptName"
              header-align="center"
              align="center"
              width="120"
              label="部门"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              v-if="show"
              prop="deptId"
              header-align="center"
              align="center"
              label="部门id"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="gwmc"
              header-align="center"
              align="center"
              width="120"
              label="岗位"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              v-if="show"
              prop="gwid"
              header-align="center"
              align="center"
              label="岗位id"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column align="center" label="测评">
              <el-table-column
                prop="cpScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="cpQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="日常考核">
              <el-table-column
                prop="rcScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="rcQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="业绩合同">
              <el-table-column
                prop="htScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="htQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="重点任务">
              <el-table-column
                prop="rwScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="rwQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="工作任务书">
              <el-table-column
                prop="gzScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="gzQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column
              prop="xs"
              header-align="center"
              align="center"
              width="120"
              label="系数"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="zhdf"
              header-align="center"
              align="center"
              width="120"
              fixed="right"
              label="汇总得分"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="zzdf"
              header-align="center"
              align="center"
              width="120"
              fixed="right"
              label="最终得分"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="pfdj"
              header-align="center"
              align="center"
              width="140"
              fixed="right"
              label="评分等级"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <!--新增-->
                <el-select
                  v-model="scope.row.pfdj"

                  @change="getPfdj(scope.row, scope.$index)"
                  placeholder="请选择"
                  class="xiaLa"
                  style="width: 100%"
                  :clearable="true"

                >
                  <el-option
                    v-for="(item, index) in pfdjsList"
                    :key="index"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>

              </template>
            </el-table-column>
          </el-table>
        </div>
       <!-- <UserCommonSelect v-if="usercomment" ref="usercomment"  @refresh="refresh" :zid="zid"></UserCommonSelect>-->
      </div>


      </div>
      </div>
     <!-- <ScoreZxForm ref="eventzxRef" :scorezxForm="dataForm" :zid="zid"></ScoreZxForm>-->
<!--      子列表-->
     <!-- <span slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="closeDialog()">返回</el-button>
        <el-button  type="primary" plain @click="saveFormData">确定</el-button>
      </span>-->


  </div>
</template>

<script>

    // 接口 api
    import {
        submitGrade,
        getMxListQuery,
        getPfdjList
    } from "@/api/statisticsanalysis/pfhzbmhzApi.js";
    export default {
        components: {
           // UserCommonSelect
        },
        props: {
            dialogTitle: String
        },
        data() {

            return {
                canSubmit: true,
                zbgz: false,
                fsgz: false,
                visible: false, //最外弹窗显隐
                searchadvanced: true,
                searchheight: "0",
                fullscreenLoading: false,
                scoreForm:{
                },
                //dataForm:{},
                checkAll: false,
                checkedBms: [], // 初始选中的值
                bmsArr: [], //一共有多少个选项
                isIndeterminateBm: false, // 全选框是否在勾选状态

                checkAllGw: false,
                checkedGws: [], // 初始选中的值
                gwsArr: [], //一共有多少个选项
                isIndeterminateGw: false, // 全选框是否在勾选状态
                zid:'',
                tabType: "1",
                scorezxForm: {},
                usercomment: false, //人员选择显隐
                show:false,
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                type: 0,
                index: 1,
                dataList: [],
                dataListLoading: false,
                dialogVisible: false,
                pfgzsList : [
                    { name: "自由选择", value: "1" },
                    { name: "占比规则", value: "2" },
                    { name: "分数区间", value: "3" },
                ],
                pfdjsList : [
                    /*{ name: "A+", value: "A+" },
                    { name: "A", value: "A" },
                    { name: "B", value: "B" },
                    { name: "C", value: "C" },
                    { name: "D", value: "D" },*/
                ],
                dataRule: {
                    pfgz: [
                        {required: true, message: "请选择评分规则", trigger: "change"},
                    ],
                },
                rungo:true,
            }
        },
        watch: {},
        created() {

        },

        methods: {
            init(obj) {
                this.visible = true;
                this.zid = obj.id;
                if (obj.state == 0 || obj.state == 3) {
                    this.canSubmit = false;
                } else {
                    this.canSubmit = true;
                }
                this.getDataList();
                this.getfpgzbzList(obj);



                this.scoreForm = obj;
                if(obj.pfgz == null){

                    this.$set(this.scoreForm,'pfgz','1');

                }
                if(this.scoreForm.pfgz ==2){
                    this.zbgz = true;
                    this.fsgz = false;
                }
                if(this.scoreForm.pfgz ==3){
                    this.fsgz = true;
                    this.zbgz = false;
                }

            },
            // 勾选数据
            handleSelectionChange(val) {
                let isSubmit = val.every(it => {
                    return it.state == 1 || it.state == 2;
                });
                if (val.length == 0) {
                    this.canSubmit = true;
                } else {

                    if (isSubmit) {
                        this.canSubmit = false;
                    } else {
                        this.canSubmit = true;
                    }
                }
                this.multipleSelection = val;
            },

            selectSecondSelect(){
                //选择的时候强制刷新
                this.$forceUpdate()
            },
            getfpgzbzList(obj){

                    let item1 = {
                        name: obj.ajszb,
                        value: obj.ajszb
                    }
                    this.pfdjsList.push(item1)

                    let item2 = {
                        name: obj.aszb,
                        value: obj.aszb
                    }
                    this.pfdjsList.push(item2)

                    let item3 = {
                        name: obj.bszb,
                        value: obj.bszb
                    }
                    this.pfdjsList.push(item3)

                    let item4 = {
                        name: obj.cszb,
                        value: obj.cszb
                    }
                    this.pfdjsList.push(item4)

                    let item5 = {
                        name: obj.dszb,
                        value: obj.dszb
                    }
                    this.pfdjsList.push(item5)

                    let item6 = {
                        name: obj.eszb,
                        value: obj.eszb
                    }
                    this.pfdjsList.push(item6)

                    let item7 = {
                        name: obj.fszb,
                        value: obj.fszb
                    }
                    this.pfdjsList.push(item7)

            },
            getFpgz(val){
                // 自由选择
                if(val == 1){
                    /*this.dataList.map(it =>{
                        let arr =  [
                            { name: "A+", value: "A+" },
                            { name: "A", value: "A" },
                            { name: "B", value: "B" },
                            { name: "C", value: "C" },
                            { name: "D", value: "D" },
                        ];
                      this.$set(it,"pfdjsList",arr);

                    })*/
                    this.zbgz = false;
                    this.fsgz = false;
                    this.$set(this.scoreForm,"ajsz","0");
                    this.$set(this.scoreForm,"asz","0");
                    this.$set(this.scoreForm,"bsz","0");
                    this.$set(this.scoreForm,"csz","0");
                    this.$set(this.scoreForm,"dsz","0");
                    this.$set(this.scoreForm,"esz","0");
                    this.$set(this.scoreForm,"fsz","0");
                }
                // 占比规则
                if(val == 2){

                    this.zbgz = true;
                    this.fsgz = false;
                    this.$set(this.scoreForm,"ajsz","0");
                    this.$set(this.scoreForm,"asz","0");
                    this.$set(this.scoreForm,"bsz","0");
                    this.$set(this.scoreForm,"csz","0");
                    this.$set(this.scoreForm,"dsz","0");
                    this.$set(this.scoreForm,"esz","0");
                    this.$set(this.scoreForm,"fsz","0");

                }
                // 分数区间
                if(val == 3){
                    this.fsgz = true;
                    this.zbgz = false;
                    this.$set(this.scoreForm,"ajsz","0");
                    this.$set(this.scoreForm,"asz","0");
                    this.$set(this.scoreForm,"bsz","0");
                    this.$set(this.scoreForm,"csz","0");
                    this.$set(this.scoreForm,"dsz","0");
                    this.$set(this.scoreForm,"esz","0");
                    this.$set(this.scoreForm,"fsz","0");

                }
            },
            searchchangeadvanced() {
                this.searchadvanced = !this.searchadvanced;
                if (this.searchadvanced) {
                    this.searchheight = "auto";
                }
            },
            getPfdj(){

            },
            refresh(){//刷新
                this.getDataList();
            },
            //子组件列表
            getDataList() {
                this.dataListLoading = true;
                getMxListQuery(
                    Object.assign(
                    {}
                   ),
                    this.zid
                    ).then(r => {

                    this.dataList = r.data.data;

                });
                this.dataListLoading = false;

            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val;
                this.pageIndex = 1;
                this.getDataList();
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val;
                this.getDataList();
            },
            saveFormData() {
                if(this.rungo) {
                    this.rungo = false
                    this.$refs["scoreForm"].validate(valid => {
                        if (valid) {
                            if (this.scoreForm.pfgz == undefined) {
                                this.$message.warning("请选择评分规则");
                                return false;
                            } else {
                                if (this.scoreForm.pfgz == 2) {
                                    let con = parseFloat(this.scoreForm.ajsz) + parseFloat(this.scoreForm.asz) + parseFloat(this.scoreForm.bsz) + parseFloat(this.scoreForm.csz) + parseFloat(this.scoreForm.dsz) + parseFloat(this.scoreForm.esz) + parseFloat(this.scoreForm.fsz);
                                    if (con > 100) {
                                        this.$message.warning("占比规则超100，请重新填写");
                                        return false;
                                    }
                                }

                                this.scoreForm.bmhzMxList = this.dataList;

                                submitGrade(this.scoreForm).then(r => {
                                    if (r.data.code == 0) {
                                        this.rungo = true
                                        this.$message.success("保存成功");
                                        this.getDataList();
                                    }
                                });

                            }

                        } else {
                            this.rungo = true
                            return false;
                        }
                    });
                    /*// 编辑
                this.fullscreenLoading = true;

                submitBmhzMx(this.dataList, this.zid).then(r => {
                    if (r.data.code == 0) {

                        this.fullscreenLoading = false;
                        //this.closeDialog();
                        this.fnBackOldPage("返回原页面");
                        this.$message.success("保存成功");
                    }
                });*/
                }
            },

            //返回原来的页面
            fnBackOldPage(type) {
                this.$emit("fnBackOldPage", type);
            },
            closeDialog() {
                this.visible = false;
                this.$emit("closeDialog");
            }
        }

    };
</script>
<style lang="scss" scoped>
  .fla {
    float: left;
    margin-right: 15px !important;
    margin-left: 5px;
  }
</style>
